<%@page import="com.mbbcpa.util.StringUtils"%>
<%@ page import = "java.util.Map" %>
<%@ page import = "java.util.HashMap" %>
<%@ page import = "java.util.ArrayList" %>
<%@ page import = "java.util.Iterator" %>
<%@ page import = "com.mbbcpa.util.Constants" %>

<%@ page import = "com.mbbcpa.security.dao.SecUserDao" %>
<%@ page import = "com.mbbcpa.security.dao.SecAccessDao" %>

<%
String msg = StringUtils.NullSafe((String) request.getAttribute("msg"));
String msg_id = StringUtils.NullSafe((String) request.getAttribute("msg_id"));

String oldpass = StringUtils.NullSafe((String) request.getAttribute("oldpass"));
String pass1 = StringUtils.NullSafe((String) request.getAttribute("pass1"));
String pass2 = StringUtils.NullSafe((String) request.getAttribute("pass2"));

boolean showParam = false;
String msgColor = "red";

if (msg_id.equalsIgnoreCase("MSG001") || msg_id.equalsIgnoreCase("MSG002"))
	showParam = true;

if (msg_id.equalsIgnoreCase("MSG999"))
	msgColor = "green";

ArrayList secGroupAccessList = (ArrayList) session.getAttribute(Constants.LOGON_ACCESS_LIST);
SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);
String sUserName = oSecUserDao.getUserName();
String lastLogonDateTime = StringUtils.NullSafe((String) session.getAttribute(Constants.LAST_LOGON_DATETIME));

String selected = "changepwd";
int iManualCP = 0;	//MAN000
int iSecMan = 0;	//SEC000
int iFAQ = 0;		//FAQ000
int iExempt = 0;	//EXE000
int iChangePW = 0;	//CPW000
int iRefMan = 0;	//RFM000
int iUserGuid = 0;	//USG000


for(int i=0;i<secGroupAccessList.size();i++){
	SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
	String strModuleCode  = secaccessDao.getModuleCode();
	if(strModuleCode.equals("MAN000"))
		iManualCP = 1;
	if(strModuleCode.equals("SEC000"))
		iSecMan = 1;
	if(strModuleCode.equals("FAQ000"))
		iFAQ = 1;
	if(strModuleCode.equals("EXE000"))
		iExempt = 1;
	if(strModuleCode.equals("CPW000"))
		iChangePW = 1;
	if(strModuleCode.equals("RFM000"))
		iRefMan = 1;
	if(strModuleCode.equals("USG000"))
		iUserGuid = 1;
}
%>
<script type="text/javascript">
	function ChangePwd(){
		var frm = document.ChangePwdForm;
		if (frm.oldpass.value == ""){
			alert("Current Password is Required.");
			frm.oldpass.focus();
			return;
		}
		if (frm.pass1.value == ""){
			alert("New Password is Required.");
			frm.pass1.focus();
			return;
		}
		if (frm.pass2.value == ""){
			alert("New Password Confirmation is Required.");
			frm.pass2.focus();
			return;
		}
		if (!(frm.pass1.value == frm.pass2.value)){
			alert("Passwords are not equal. Please try again.");
			return;
		}
		if (frm.oldpass.value == frm.pass1.value){
			alert("New Password must not be equal to current password.");
			return;
		}
		
		frm.action = "UserAction.do?dispatch=changeInitial";
		frm.submit();
	}
	
</script>
<link href="resource/style.css" rel="stylesheet" type="text/css">
	
	<script type="text/javascript">
	    window.history.forward();
	    function noBack() { window.history.forward(); }
	</script>
<style type="text/css"></style></head>

<body class="home" onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
	<a name="top"></a>
	
<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->


	<div id="bgWrapper">
		<div id="container">

			<div id="titleBar">
				<ul class="topBar">
					<li class="goBackBt"><a href="<%=request.getContextPath()%>/CheckUserLogon.do?dispatch=homePage"></a></li>
					<li>
					  <h1>Change Password</h1></li>
				</ul>
			</div>

			<div id="fullcontent">

<!-- Root Navigation -->
<%@ include file="RootNavigation.jsp" %>	
<!-- Root SecurityNavigation -->

<div id="contentRightIn">
	<form name="ChangePwdForm" method="post">
	<table align="center" class="tblInput" width=90% border="0" rules="cols">
			<thead class="th1">
				<tr>
					<th colspan="2">
						<div class="sectionTableTitle">
							<h4>Change Password</h4>
						</div>
					</th>
			</thead>
			<tr <%=msg_id.equals("MSG999")?"style=\"display:none\"":"" %>>
				<td width="40%" class="center_note">Old Password</td>
				<td width="40%" class="center_note"><input class="inputStyle" type="password" name="oldpass" value="<%=showParam?oldpass:""%>"></td>
			</tr>
			<tr <%=msg_id.equals("MSG999")?"style=\"display:none\"":"" %>>
				<td width="40%" class="center_note">New Password</td>
				<td width="40%" class="center_note"><input class="inputStyle" type="password" name="pass1" value="<%=showParam?pass1:""%>"></td>
			</tr>
			<tr <%=msg_id.equals("MSG999")?"style=\"display:none\"":"" %>>
				<td width="40%" class="center_note">Confirm New Password</td>
				<td width="40%" class="center_note"><input class="inputStyle" type="password" name="pass2" value="<%=showParam?pass2:""%>"></td>
			</tr>
			<tr align="center" <%=msg_id.equals("MSG999")?"style=\"display:none\"":"" %>>
				<td width="40%" class="center_note" colspan="2"><input class="inputButton clearfix" type="button" name="reset" value="Submit" onClick="JavaScript:ChangePwd();"></td>
			</tr>
			<tr align="center" <%=msg_id.equals("MSG999")?"":"style=\"display:none\"" %>>
				<td width="40%" class="center_note" colspan="2"><a href="<%=request.getContextPath()%>/LogOut.do?dispatch=init""><span><input class="inputButton clearfix" type="button" name="reset" value="OK"></span></a></td>
			</tr>
	</table>
	<div id="contentMessage">
		<h3 class="<%=msgColor%>"><%=msg%></h3>
	</div>
	
	</form>
</div>
				
</div>

<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->
</div>
</div>